<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Customer status</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script type="text/javascript" src="common.js"></script>
    <script type="text/javascript">

        function dispTableHdlr(xml_doc) {
            //TODO: Handle the response from the server for the save command
            xmlDoc=loadXMLString(xml_doc);

            result=xmlDoc.getElementsByTagName("result");
            try {
                result_text = result[0].firstChild.nodeValue;
            } catch (er) {
                result_text = "Error";
            }
            table_text = "<button onclick='queryForm()'>Display the customer details</button>";
            table_text = table_text + "<table border='1'>";

            switch (result_text.toLowerCase()) {
                case "success":
                    //alert('Successful query');
                    customers=xmlDoc.getElementsByTagName("customer");
                    try {
                        table_text = table_text + "<tr><td><b>ID</b></td>";
                        table_text = table_text + insertField(customers[0], "cust_id");
                        table_text = table_text + "</tr><tr><td><b>Name</b></td>";
                        table_text = table_text + insertField(customers[0], "cust_name");
                        table_text = table_text + "</tr><tr><td><b>Centre Code</b></td>";
                        table_text = table_text + insertField(customers[0], "centre_code");
                        table_text = table_text + "</tr><tr><td><b>Agent Code</b></td>";
                        table_text = table_text + insertField(customers[0], "agent_code");
                        table_text = table_text + "</tr><tr><td><b>Film Code</b></td>";
                        table_text = table_text + insertField(customers[0], "film_code");
                        table_text = table_text + "</tr><tr><td><b>Ticket number</b></td>";
                        table_text = table_text + insertField(customers[0], "ticket_no");
                        table_text = table_text + "</tr><tr><td><b>Phone</b></td>";
                        table_text = table_text + insertField(customers[0], "phone");
                        table_text = table_text + "</tr><tr><td><b>Date of issue</b></td>";
                        table_text = table_text + insertField(customers[0], "date_issue");
                        table_text = table_text + "</tr><tr><td><b>Time of issue</b></td>";
                        table_text = table_text + insertField(customers[0], "time_issue");
                        table_text = table_text + "</tr><tr><td><b>Ticket rate</b></td>";
                        table_text = table_text + insertField(customers[0], "ticket_rate");
                        table_text = table_text + "</tr><tr><td><b>Status</b></td>";
                        table_text = table_text + insertField(customers[0], "value");
                        table_text = table_text + "</tr>";
                    } catch (er) {
                        alert('Invalid ticket number');
                    }
                    break;
                case "login":
                    alert("Login required. You will now be redirected to the login page");
                    window.location="login.html";
                    break;
                case "error":
                default:
                    alert("Error occured while processing the query response");
                    break;
            }

            table_text = table_text + "</table>";
            document.getElementById("cust_table").innerHTML=table_text;
        }

        function queryForm() {
            var ticket_no=document.getElementById("ticket_no").value;
            srvr_request="querycustomer.php?ticket_no="+ticket_no;
            ajaxCall(srvr_request,dispTableHdlr);
        }

        function dispTreeHdlr(xml_doc) {
            //TODO: Handle the response from the server for the save command
            xmlDoc=loadXMLString(xml_doc);

            result=xmlDoc.getElementsByTagName("result");
            try {
                result_text = result[0].firstChild.nodeValue;
            } catch (er) {
                result_text = "Error";
            }
            table_text = "<button onclick='displayTree()'>Display the customer tree</button>";
            table_text = table_text + "<table border='1' id='cust_tree_table'>"+
                      "<tr><th>Level</th>"+
                          "<th>Ticket number</th>"+
                          "<th>Parent ticket number</th>"+
                          "<th>Max coupon value</th>"+
                          "<th>Status</th></tr>";

            switch (result_text.toLowerCase()) {
                case "success":
                    //alert('Successful query');
                    agents=xmlDoc.getElementsByTagName("ticket");
                    for (i=0;i<agents.length;i++) {
                        level=agents[i].getElementsByTagName("level");
                        switch(level[0].firstChild.nodeValue) {
                            case '0':
                                color="red";
                                break;
                            case '1':
                                color="blue";
                                break;
                            case '2':
                                color="green";
                                break;
                            default:
                                color="white";
                                break;
                        }
                        table_text = table_text + "<tr>";
                        try {
                            table_text = table_text + insertField(agents[i], "level", color);
                            table_text = table_text + insertField(agents[i], "ticket_no");
                            table_text = table_text + insertField(agents[i], "parent_ticket_no");
                            table_text = table_text + insertField(agents[i], "max_coupon_value");
                            table_text = table_text + insertField(agents[i], "value");
                        } catch (er) {
                            alert('Invalid ticket number');
                        }
                        table_text = table_text + "</tr>";
                    }
                    break;
                case "login":
                    alert("Login required. You will now be redirected to the login page");
                    window.location="login.html";
                    break;
                case "error":
                default:
                    alert("Error occured while processing the query response");
                    break;
            }

            table_text = table_text + "</table>";
            document.getElementById("cust_tree").innerHTML=table_text;
            f_sort( document.all.cust_tree_table, 0, true );
        }

        function displayTree() {
            var ticket_no=document.getElementById("ticket_no").value;
            srvr_request="customertree.php?ticket_no="+ticket_no;
            ajaxCall(srvr_request,dispTreeHdlr);
        }

    </script>

  </head>
  <body>
      <table border="1">
          <tr><td width="150"><a href="producer.html"><b>Producers</b></a></td>
              <td width="150"><a href="film.html"><b>Films</b></a></td>
              <td width="150"><a href="centre.html"><b>Centres</b></a></td>
              <td width="150"><a href="agent.html"><b>Agents</b></a></td>
              <td width="150"><a href="customer.html"><b>Tickets</b></a></td>
              <td width="150"><a href="ticket.html"><b>Ticket rate information</b></a></td>
              <td width="150"><a href="ticketstatus.html"><b>Status of ticket sales for each film</b></a></td>
              <td width="150"><a href="customerstatus.html"><b>Status for each customer</b></a></td>
              <td width="150"><a href="logout.php"><b>Logout</b></a></td></tr>
      </table>

        <table border="0">

            <tr><td><label>Ticket number&nbsp;*</label></td>
                <td><input id="ticket_no" type=text size='20' value=''></td>
                <td><div id="ticket_no_hint"> </div></td></tr>

        </table>
        <div id="cust_table">
            <button onclick="queryForm()">Display the customer details</button>
        </div>

        <div id="cust_tree">
            <button onclick="displayTree()">Display the customer tree</button>
        </div>

  </body>
</html>
